import 'package:ati_package/core/extension/ati_widgets_extension.dart';
import 'package:ati_package/core/routes/app_routes.dart';
import 'package:ati_package/core/utils/ati_assets.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/core/utils/ati_enum.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class UserFWidget extends StatelessWidget {
  const UserFWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10.r),
      decoration: BoxDecoration(color: AtiColor.pageColor),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,

        children: [
          _buildSectionTitle('积分订单'),
          _buildListSection([
            {
              'icon': AtiAssets.userOrderqbdh,
              'label': '全部兑换',
              'type': UserCenterModel.userCenterOrderqbdh,
            },
            {
              'icon': AtiAssets.userOrderdfh,
              'label': '待发货',
              'type': UserCenterModel.userCenterOrderdfh,
            },
            {
              'icon': AtiAssets.userOrderdsh,
              'label': '待收货',
              'type': UserCenterModel.userCenterOrderdsh,
            },
            {
              'icon': AtiAssets.userOrderywc,
              'label': '已完成',
              'type': UserCenterModel.userCenterOrderywc,
            },
          ]),

          // SizedBox(height: 20.h),
          _buildSectionTitle('全职管理'),
          _buildListSection([
            {
              'icon': AtiAssets.userAccountsmrz,
              'label': '实名认证',
              'type': UserCenterModel.userCenterAccountsmrz,
            },
            {
              'icon': AtiAssets.userAccountqbdz,
              'label': '钱包地址',
              'type': UserCenterModel.userCenterAccountqbdz,
            },
            {
              'icon': AtiAssets.userAccountdlmm,
              'label': '登录密码',
              'type': UserCenterModel.userCenterAccountdlmm,
            },
            {
              'icon': AtiAssets.userAccountjymm,
              'label': '交易密码',
              'type': UserCenterModel.userCenterAccountjymm,
            },
          ]),
          _buildSectionTitle('其他功能'),
          _buildListSection([
            {
              'icon': AtiAssets.userOthershdz,
              'label': '收货地址',
              'type': UserCenterModel.userCenterOthershdz,
            },
            {
              'icon': AtiAssets.userOtherlyb,
              'label': '留言板',
              'type': UserCenterModel.userCenterOtherlyb,
            },
            {
              'icon': AtiAssets.userOthergfwz,
              'label': '官方网站',
              'type': UserCenterModel.userCenterOthergfwz,
            },
            {
              'icon': AtiAssets.userOthergywm,
              'label': '关于我们',
              'type': UserCenterModel.userCenterOthergywm,
            },
            {
              'icon': AtiAssets.userOthersz,
              'label': '设置',
              'type': UserCenterModel.userCenterOthersz,
            },
            {
              'icon': AtiAssets.userOtherqhyy,
              'label': '切换语言',
              'type': UserCenterModel.userCenterOtherqhyy,
            },
          ]),
        ],
      ),
    );
  }

  _buildSectionTitle(String title) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 16.r),
      child: Text(
        title,
        style: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w600,
          color: Colors.black87,
        ),
      ),
    );
  }

  Widget _buildListSection(List<Map<String, dynamic>> items) {
    return Container(
      padding: EdgeInsets.only(left: 10.r, right: 10.r, bottom: 10.r),
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.r)),
      child: Wrap(
        spacing: 10.r,
        runSpacing: 10.r,
        alignment: WrapAlignment.start,
        children: items.map((item) {
          return SizedBox(
            width: (1.sw - 60.r) / 4, // 4列布局，留出左右+间距
            child: _buildGridItem(item['icon'], item['label'], item['type']),
          );
        }).toList(),
      ),
    );
  }

  // 🕹 每个格子元素
  Widget _buildGridItem(
    String iconStr,
    String label,
    UserCenterModel centerModel,
  ) {
    return InkWell(
      borderRadius: BorderRadius.circular(8.r),
      onTap: () {
        // TODO: 点击事件
      },
      child:
          Container(
            padding: EdgeInsets.symmetric(vertical: 8.h),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset(
                  width: iconStr.contains('order') == true ? 40.r : 30.r,
                  height: iconStr.contains('order') == true ? 40.r : 30.r,
                  iconStr,
                  package: 'ati_package',
                ),
                SizedBox(height: 6.r),
                Text(
                  label,
                  style: TextStyle(
                    fontSize: 13.sp,
                    color: const Color(0xFF333333),
                  ),
                ),
              ],
            ),
          ).addTapGesture(
            onTap: () {
              switch (centerModel) {
                case UserCenterModel.userCenterOrderqbdh:
                  {
                    Get.toNamed(AtiAppRoutes.userOrderRecord);
                  }
                  break;
                case UserCenterModel.userCenterOrderdfh:
                  {}
                  break;
                case UserCenterModel.userCenterOrderdsh:
                  {}
                  break;
                case UserCenterModel.userCenterOrderywc:
                  {}
                  break;
                case UserCenterModel.userCenterAccountsmrz:
                  {
                    Get.toNamed(AtiAppRoutes.userRwalNameInput);
                  }
                  break;
                case UserCenterModel.userCenterAccountqbdz:
                  {
                    Get.toNamed(AtiAppRoutes.userWalletAddress);
                  }
                  break;
                case UserCenterModel.userCenterAccountdlmm:
                  {
                    Get.toNamed(AtiAppRoutes.userChangeLigonPassword);
                  }
                  break;
                case UserCenterModel.userCenterAccountjymm:
                  {
                    Get.toNamed(AtiAppRoutes.userChangeTransPassword);
                  }
                  break;
                case UserCenterModel.userCenterOthershdz:
                  {
                    //收货地址
                    Get.toNamed(AtiAppRoutes.userAddress);
                  }
                  break;
                case UserCenterModel.userCenterOthergfwz:
                  {
                    Get.toNamed(
                      AtiAppRoutes.atiWebShow,
                      arguments: {
                        'url':
                            'https://pub-web.flutter-io.cn/packages/screenshotx/versions',
                        'title': '官方网站',
                      },
                    );
                  }
                  break;
                case UserCenterModel.userCenterOthergywm:
                  {
                    Get.toNamed(AtiAppRoutes.userAboutUs);
                  }
                  break;
                case UserCenterModel.userCenterOthersz:
                  {
                    Get.toNamed(AtiAppRoutes.userSetting);
                  }
                  break;
                case UserCenterModel.userCenterOtherqhyy:
                  {}
                  break;
                default:
                  {}
                  break;
              }
            },
          ),
    );
  }
}
